package com.itheima.health.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.pojo.Setmeal;
import com.itheima.health.vo.CheckGroupVO;
import com.itheima.health.vo.SetmealVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface SetmealMapper extends BaseMapper<Setmeal> {
    @Insert("insert into t_setmeal_checkgroup values(#{sid},#{gid})")
    void addSetmealAndCheckGroupIds(@Param("sid") int sid, @Param("gid") Integer gid);

    @Select("select id,PRICE,ATTENTION,code,name,age,sex,HELPCODE,remark,img from t_setmeal where id =#{id}")
    SetmealVO findSetmealById(@Param("id") int id);

    @Select("SELECT tc.id,tc.name,tc.REMARK " +
            "FROM  t_setmeal_checkgroup tsc ,t_checkgroup tc " +
            "WHERE  tsc.CHECKGROUP_ID = tc.ID " +
            "and tsc.SETMEAL_ID=#{id}")
    List<CheckGroupVO> findCheckGroupListBySetmealId(@Param("id") int id);

    @Select("SELECT tc.name " +
            "FROM t_checkgroup_checkitem tcc , t_checkitem tc " +
            "WHERE tcc.CHECKITEM_ID = tc.ID " +
            "and tcc.CHECKGROUP_ID = #{id}")
    List<CheckItem> findCheckItemByGroupId(@Param("id") Integer id);


    @Select("select  CHECKGROUP_ID from t_setmeal_checkgroup where SETMEAL_ID = #{id}")
    int[] findCheckGroupIdsByGroupId(@Param("id") int id);


    @Delete("delete from t_setmeal_checkgroup where SETMEAL_ID = #{sid}")
    void deleteCheckGroupIdsBySetmealId(@Param("sid")Integer sid);

    @Select("select id,name,age,sex,remark,img from t_setmeal where is_delete=0")
    List<Setmeal> findAllSetmeal();

    @Select("select img from t_setmeal where id = #{sid}")
    String selectImgById(@Param("sid")Integer sid);
}
